from PyQt5.QtCore import Qt


def addTooltipInSpinBox(spbox, rng):
    """set range and add tooltip for spinbox widget"""
    spbox.setRange(*rng)
    spbox.setToolTip("范围 {0}{2} ~ {1}{2}".format(spbox.minimum(), spbox.maximum(), spbox.suffix()))


def dealGroubBpxDoubleClick(ws, e):
    idx = (Qt.LeftButton, Qt.MidButton, Qt.RightButton).index(e.button())
    if idx == 0:  # left button double click
        for ws in ws:
            ws.setChecked(not ws.isChecked())
    elif idx == 1:  # middle button double click
        for ws in ws:
            ws.setChecked(False)
    elif idx == 2:  # right button double click
        for ws in ws:
            ws.setChecked(True)
